package com.cryptape.cita_wallet.net.request;

import android.app.Activity;
import android.content.Context;

import com.cryptape.cita_wallet.bean.BindHashBean;
import com.cryptape.cita_wallet.bean.CouldOrderBean;
import com.cryptape.cita_wallet.bean.LightNodeBean;
import com.cryptape.cita_wallet.bean.MarkIndexBean;
import com.cryptape.cita_wallet.bean.MiningOrderIncomeBean;
import com.cryptape.cita_wallet.bean.MiningWithdrawDetailBean;
import com.cryptape.cita_wallet.bean.MortgageAssociationBean;
import com.cryptape.cita_wallet.bean.MortgageMiningBean;
import com.cryptape.cita_wallet.bean.MyHMIOOrderBean;
import com.cryptape.cita_wallet.bean.MyMIDBean;
import com.cryptape.cita_wallet.bean.MyOrderWalletBean;
import com.cryptape.cita_wallet.bean.NetworkWideMortgageBean;
import com.cryptape.cita_wallet.bean.VStimulateBean;
import com.cryptape.cita_wallet.bean.VersionUpdateBean;
import com.cryptape.cita_wallet.net.callback.CommonCallback;
import com.cryptape.cita_wallet.net.common.NetWorkManager;
import com.cryptape.cita_wallet.net.common.RxSubscriber2;
import com.cryptape.cita_wallet.net.response.BaseResponse;

import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;

public class HttpRequestMode {
    /**
     * 提取收益首页
     */
    public static void getWithdrawIndex(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().getWithdrawIndex(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse<MiningWithdrawDetailBean>>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse<MiningWithdrawDetailBean> data) {
                        try {
                            if (data.isSuccess()) {
                                callback.onSuccess(data.getData(), "", 0);
                            } else {
                                callback.onFailure(data.getMessage(), 0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 获取mid
     */
    public static void findMid(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().findMid(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse<MyMIDBean>>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse<MyMIDBean> data) {
                        try {
                            if (data.isSuccess()) {
                                callback.onSuccess(data.getData(), "", 0);
                            } else {
                                callback.onFailure(data.getMessage(), 0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 实时数据
     */
    public static void getRealTimeIndex(Activity context, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().getRealTimeIndex()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse<NetworkWideMortgageBean>>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse<NetworkWideMortgageBean> data) {
                        try {
                            if (data.isSuccess()) {
                                callback.onSuccess(data.getData(), "", 0);
                            } else {
                                callback.onFailure(data.getMessage(), 0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 转账记录
     */
    public static void getTransferRecord(Activity context, String content, boolean isShowLoading) {
        NetWorkManager.getRequest().getTransferRecord(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                    }
                });
    }

    /**
     * 推送绑定
     */
    public static void getBindRegistration(Activity context, String content, boolean isShowLoading) {
        NetWorkManager.getRequest().getBindRegistration(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                    }
                });
    }

    /**
     * 推送全部检测
     */
    public static void getAllDetection(Activity context, String content, boolean isShowLoading) {
        NetWorkManager.getRequest().getAllDetection(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                    }
                });
    }

    /**
     * 保存当前语言
     */
    public static void saveCurrentLanguage(Activity context, String content, boolean isShowLoading) {
        NetWorkManager.getRequest().saveCurrentLanguage(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                    }
                });
    }

    /**
     * 获取当前语言
     * type 类型0英文(默认)1中文2日文3韩文
     */
    public static void getCurrentLanguage(Activity context, String content, boolean isShowLoading) {
        NetWorkManager.getRequest().getCurrentLanguage(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                    }
                });
    }

    /**
     * 实时数据
     */
    public static void getAddOrder(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().getAddOrder(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            if (data.isSuccess()) {
                                callback.onSuccess(data.getData(), "", 0);
                            } else {
                                callback.onFailure(data.getMessage(), 0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 实时数据
     */
    public static void getVersion(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().getVersion(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse<VersionUpdateBean>>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            if (data.isSuccess()) {
                                callback.onSuccess(data.getData(), "", 0);
                            } else {
                                callback.onFailure(data.getMessage(), 0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 挖矿抵押
     */
    public static void getOrderIndex(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().getOrderIndex(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse<MortgageMiningBean>>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            if (data.isSuccess()) {
                                callback.onSuccess(data.getData(), "", 0);
                            } else {
                                callback.onFailure(data.getMessage(), 0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 社群
     */
    public static void getMortgage(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().getMortgage(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse<MortgageAssociationBean>>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            if (data.isSuccess()) {
                                callback.onSuccess(data.getData(), "", 0);
                            } else {
                                callback.onFailure(data.getMessage(), 0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 节点页面
     */
    public static void getNodeIndex(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().getNodeIndex(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse<LightNodeBean>>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            if (data.isSuccess()) {
                                callback.onSuccess(data.getData(), "", 0);
                            } else {
                                callback.onFailure(data.getMessage(), 0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 我的激励
     */
    public static void getMyOrderWallet(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().getMyOrderWallet(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse<MyOrderWalletBean>>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            if (data.isSuccess()) {
                                callback.onSuccess(data.getData(), "", 0);
                            } else {
                                callback.onFailure(data.getMessage(), 0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 指数
     */
    public static void getIndexMarkIndex(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().getIndexMarkIndex(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse<MarkIndexBean>>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            if (data.isSuccess()) {
                                callback.onSuccess(data.getData(), "", 0);
                            } else {
                                callback.onFailure(data.getMessage(), 0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 获取我的云矿机
     */
    public static void getMyHMioOrders(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().getMyHMioOrders(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse<MyHMIOOrderBean>>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            if (data.isSuccess()) {
                                callback.onSuccess(data.getData(), "", 0);
                            } else {
                                callback.onFailure(data.getMessage(), 0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 云矿机收益明细
     */
    public static void getMiningOrderIncome(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().getMiningOrderIncome(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse<MiningOrderIncomeBean>>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            if (data.isSuccess()) {
                                callback.onSuccess(data.getData(), "", 0);
                            } else {
                                callback.onFailure(data.getMessage(), 0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 绑定mid
     */
    public static void bindMid(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().bindMid(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse<MyMIDBean>>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            if (data.isSuccess()) {
                                callback.onSuccess(data.getData(), "", 0);
                            } else {
                                callback.onFailure(data.getMessage(), 0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 绑定mid
     */
    public static void getCouldOrder(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().getCouldOrder(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse<List<CouldOrderBean>>>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            if (data.isSuccess()) {
                                callback.onSuccess(data.getData(), "", 0);
                            } else {
                                callback.onFailure(data.getMessage(), 0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 绑定地址
     */
    public static void bindAddress(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().bindAddress(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            if (data.isSuccess()) {
                                callback.onSuccess(data.getData(), "", 0);
                            } else {
                                callback.onFailure(data.getMessage(), 0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 获取V等级
     */
    public static void getVGrade(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().getVGrade(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse<VStimulateBean>>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            if (data.isSuccess()) {
                                callback.onSuccess(data.getData(), "", 0);
                            } else {
                                callback.onFailure(data.getMessage(), 0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 检测绑定地址
     */
    public static void checkBind(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().checkBind(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            callback.onSuccess(data, "", 0);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 上传mgp转账记录
     */
    public static void saveTransferHash(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().saveTransferHash(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            if (data.isSuccess()) {
                                callback.onSuccess(data.getData(), "", 0);
                            } else {
                                callback.onFailure(data.getMessage(), 0);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 检测地址或账户名是否绑定
     */
    public static void checkAddr(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().checkAddr(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            callback.onSuccess(data, "", 0);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 绑定地址
     */
    public static void bindMgpChain(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().bindMgpChain(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            callback.onSuccess(data, "", 0);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 检查绑定MID的地址是否在绑定中
     */
    public static void isFindMIDBinding(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().isFindMIDBinding(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            callback.onSuccess(data, "", 0);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 映射hash记录
     */
    public static void getSaveLog(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().getSaveLog(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse<List<BindHashBean>>>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            callback.onSuccess(data, "", 0);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }

    /**
     * 撤销映射hash
     */
    public static void resetSaveLog(Activity context, String content, boolean isShowLoading, CommonCallback callback) {
        NetWorkManager.getRequest().resetSaveLog(content)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new RxSubscriber2<BaseResponse>(context, isShowLoading) {
                    @Override
                    public void onFail(String failMsg) {
                        callback.onFailure(failMsg, 0);
                    }

                    @Override
                    public void onSuccess(BaseResponse data) {
                        try {
                            callback.onSuccess(data, "", 0);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }
                });
    }
}
